<?php

function tradesman_average_feedback($id){

$sql = "SELECT AVG(rating) AS avg_feedback FROM reviews WHERE tradesman_id = '".mysql_real_escape_string($id)."' GROUP BY tradesman_id"; 
$query=mysql_query( $sql ) or die ("Error in query: $sql . " . mysql_error());
$rs=mysql_fetch_assoc($query);

$average_feedback = ($rs['avg_feedback'] > 0) ? round($rs['avg_feedback']) : 0;

return $average_feedback;

}

?>